package cn.ekuma.epos.security.dao;

import java.util.List;

import e.odbo.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.security.db.table.I_RoleAuthorizePermission;
import cn.ekuma.security.bean.I_Permission;
import cn.ekuma.security.impl.Permission;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class PermissionDAO extends ModifiedLogDAO<Permission>{

	public PermissionDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                    "ROLE_PERMISSION",
                    new Field[]{
                       new Field(I_RoleAuthorizePermission.ID,Datas.STRING, Formats.STRING),
                       new Field(I_RoleAuthorizePermission.ROLEID,Datas.STRING, Formats.STRING),
                       new Field(I_RoleAuthorizePermission.PERMISSIONID,Datas.INT, Formats.INT), 
                       new Field(I_RoleAuthorizePermission.EXTPERMISSION,Datas.INT, Formats.INT),
                       new Field(I_RoleAuthorizePermission.MODELNAME,Datas.STRING, Formats.STRING), 
                       new Field(I_RoleAuthorizePermission.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP),
                       new Field(I_RoleAuthorizePermission.BASESECURITYNAME,Datas.STRING, Formats.STRING),
                       new Field(I_RoleAuthorizePermission.MEMO,Datas.STRING, Formats.STRING)
                     },
                    new int[]{0}
                    );
    }

    @Override
    public void writeInsertValues(DataWrite dp, Permission obj) throws BasicException {
        dp.setString(1,obj.getKey());
        dp.setString(2,obj.getRoleId());
        dp.setInt(3, obj.getPermissionId());
        dp.setInt(4, obj.getExtPermission());
        dp.setString(5, obj.getModelName());
        dp.setTimestamp(6,obj.getLastModified());
        dp.setString(7,obj.getBaseSecurityName());
        dp.setString(8, obj.getMemo());
    }

    @Override
    public Class getSuportClass() {
       return Permission.class;
    }

    public Permission readValues(DataRead dr,Permission obj) throws BasicException {
        if(obj==null)
    	  obj=new Permission();
        obj.setKey(dr.getString(1));
        obj.setRoleId(dr.getString(2));
        obj.setPermissionId(dr.getInt(3));
        obj.setExtPermission(dr.getInt(4));
        obj.setModelName(dr.getString(5));
        obj.setLastModified(dr.getTimestamp(6));
        obj.setBaseSecurityName(dr.getString(7));
        obj.setMemo(dr.getString(8));
        return obj;
    }

	public List<I_Permission> loadRolePermission(String roleId, String modeName) throws BasicException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean hasePermissionByRole(String roleId, String modeName,
			String permission)throws BasicException {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean hasePermissionByRole(String roleId, String modeName,
			String permission, String childPermission)throws BasicException {
		// TODO Auto-generated method stub
		return false;
	}
	
}
